package message;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class UpdateDataRequestMessage extends Message
{
	private static final long serialVersionUID = 1L;
	
	private boolean idSet = false;
	private int id;
	private String username;
	private String password;
	
	public int getId()
	{
		return id;
	}
	@XmlElement(name = "id", defaultValue = "-1")
	public void setId(int id)
	{
		if (!idSet)
		{
			this.id = id;
			idSet = true;
		}
	}
	public String getUsername()
	{
		return username;
	}
	@XmlElement(name = "username", required = true)
	public void setUsername(String username)
	{
		if (this.username == null)
			this.username = username;
	}
	public String getPassword()
	{
		return password;
	}
	@XmlElement(name = "password", required = true)
	public void setPassword(String password)
	{
		if (this.password == null)
			this.password = password;
	}
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		result = prime * result
				+ ((username == null) ? 0 : username.hashCode());
		
		return result;
	}
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UpdateDataRequestMessage other = (UpdateDataRequestMessage) obj;
		if (id != other.id)
			return false;
		if (password == null)
		{
			if (other.password != null)
				return false;
		}
		else if (!password.equals(other.password))
			return false;
		if (username == null)
		{
			if (other.username != null)
				return false;
		}
		else if (!username.equals(other.username))
			return false;
		
		return true;
	}
}
